//
//  SISSScanResultSucessViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/10/11.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "SISSScanResultSucessViewController.h"
#import "SISSTabBarController.h"

@interface SISSScanResultSucessViewController ()


@property (weak, nonatomic) UIImageView *imageView;
@property (weak, nonatomic) UILabel *finishTipLabel;
@property (weak, nonatomic) UILabel *finishTipInfoLabel;
@property (weak, nonatomic) UIButton *backHomeButton;
@end

@implementation SISSScanResultSucessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.title = @"扫码制作星级服务牌";
}

/// 返回首页
- (void)backHomeButtonClickAction {
    SISSTabBarController *tabBarCtr = [[SISSTabBarController alloc] init];
    [UIApplication sharedApplication].keyWindow.rootViewController = tabBarCtr;
}

- (void)setupSubviews {
    [super setupSubviews];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:self.isSuccess ? @"KPI_success" : @"X"];
    [self.view addSubview:imageView];
    self.imageView = imageView;
    
    UILabel *finishTipLabel = [UILabel yyr_labelWithText:self.isSuccess ?  @"已提交申请，请留意自助机提示" : @"扫码登录失败" fontSize:15 textColor:MAIN_TEXT_COLOR alignment:NSTextAlignmentCenter];
    [self.view addSubview:finishTipLabel];
    self.finishTipLabel = finishTipLabel;
    
    UILabel *finishTipInfoLabel = [UILabel yyr_labelWithText:self.isSuccess ? @"已提交申请，请留意自助机提示，完成后续操作；" : self.errStr fontSize:15 textColor:SECONDARY_TEXT_COLOR alignment:NSTextAlignmentCenter];
    [self.view addSubview:finishTipInfoLabel];
    self.finishTipInfoLabel = finishTipInfoLabel;
    
    UIButton *backHomeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backHomeButton setTitle:@"返回首页" forState:UIControlStateNormal];
    [backHomeButton setTitleColor:SECONDARY_TEXT_COLOR forState:UIControlStateNormal];
    [backHomeButton setBackgroundColor:UIColor.groupTableViewBackgroundColor];
    [backHomeButton addTarget:self action:@selector(backHomeButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    backHomeButton.layer.cornerRadius = 4;
    backHomeButton.layer.masksToBounds = YES;
    [self.view addSubview:backHomeButton];
    self.backHomeButton = backHomeButton;
}

- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGSize imageSize = CGSizeMake(88, 88);
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.mas_topLayoutGuideBottom).offset(3 * globelMargin);
        make.size.mas_equalTo(imageSize);
    }];
    
    [self.finishTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.imageView.mas_bottom).offset(2 * globelMargin);
        make.centerX.equalTo(weakSelf.view);
    }];
    
    [self.finishTipInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.finishTipLabel.mas_bottom).offset(2 * globelMargin);
        make.centerX.equalTo(weakSelf.view);
    }];
    
    [self.backHomeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.finishTipInfoLabel.mas_bottom).offset(4 * globelMargin);
        make.left.equalTo(weakSelf.view).offset(2 * globelMargin);
        make.right.equalTo(weakSelf.view).offset(-2 * globelMargin);
        make.height.mas_equalTo(5.5 * globelMargin);
    }];
}

@end
